package com.clstu.practice;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 这是一个用于发送文件的窗口
 */
public class SentFileFrame extends JFrame implements ActionListener {

    private JLabel pathLb = new JLabel("请输入文件路径");
    private JTextField path = new JTextField(60);
    private JLabel destLb = new JLabel("请输入目标路径");
    private JTextField dest = new JTextField(60);
    private JButton btSent = new JButton("发送");
    private JButton btExit = new JButton("退出");
    private String userID;//表示打开该窗口的用户

    public static void main(String[] args) {
        new LoginFrame();
    }

    public SentFileFrame(String userID){
        super("用户"+userID+"正在发送文件");//窗口名称
        this.userID = userID;
        this.setLayout(new FlowLayout());//设置流式布局

        this.add(pathLb);//在窗口中加入这些成员组件
        this.add(path);
        this.add(destLb);
        this.add(dest);
        this.add(btSent);
        this.add(btExit);

        this.setSize(700,190);//设置一些窗口属性
        this.setLocation(700,400);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.setVisible(true);

        btExit.addActionListener(this);//给各个按钮加入监听器
        btSent.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {//事件监听的处理

        if(e.getSource()==btSent){//如果是发送按键被按下
            String path = this.path.getText();
            String dest = new String(this.dest.getText());

            //发送文件代码

            JOptionPane.showMessageDialog(this,"发送成功");
            this.dispose();
            new MainMenu(userID);
        }else if(e.getSource()==btExit){//如果是退出按键被按下
            this.dispose();
            new MainMenu(userID);
        }else {
            JOptionPane.showMessageDialog(this,"谢谢光临");
            System.exit(0);
        }

    }
}
